# add swig python
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})

find_package(PythonLibs)

swig_add_library(ar8030_py
    LANGUAGE python
    SOURCES ar8030.i
    OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/python
)

target_include_directories(ar8030_py PRIVATE ${PYTHON_INCLUDE_PATH})
target_include_directories(ar8030_py PRIVATE ./)
swig_link_libraries(ar8030_py ${PYTHON_LIBRARIES} ar8030_client)

# origin dll
get_target_property(ar8030_client_type ar8030_client TYPE)

if(ar8030_client_type STREQUAL "SHARED_LIBRARY")
    INSTALL(TARGETS ar8030_client
        DESTINATION python
    )
endif()

# wrap.pyd
install(TARGETS ar8030_py
    DESTINATION python
)

# test code
install(FILES test.py
    DESTINATION python
)

# callback fun
set_property(SOURCE callback.i PROPERTY CPLUSPLUS ON)
swig_add_library(ar8030_callback
    LANGUAGE python
    SOURCES callback.i
    OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/python
)
target_include_directories(ar8030_callback PRIVATE ${PYTHON_INCLUDE_PATH})
target_include_directories(ar8030_callback PRIVATE ./)
swig_link_libraries(ar8030_callback ${PYTHON_LIBRARIES} ar8030_client)

# wrap.pyd
install(TARGETS ar8030_callback
    DESTINATION python
)

# wrap.py
install(
    DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/python
    DESTINATION .
    FILES_MATCHING
    PATTERN "*.py"
)
